﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JzSport.Model
{
    public class ConfigService
    {
        public ServiceResult<Config> Save(Config config)
        {
            using (JzSportDbContext dbContext = new JzSportDbContext())
            {
                ConfigRepository configReps = new ConfigRepository(dbContext);

                configReps.Save(config);

                if (dbContext.SaveChanges() > 0)
                {
                    return new ServiceResult<Config>(ErrorCode.NoError, config);
                }
                return new ServiceResult<Config>(ErrorCode.DB_Error);
            }
        }

        public ServiceResult<Config> Get(string code)
        {
            using (JzSportDbContext dbContext = new JzSportDbContext())
            {
                ConfigRepository configReps = new ConfigRepository(dbContext);

                Config config = configReps.Get(code);

                if (dbContext.SaveChanges() > 0)
                {
                    return new ServiceResult<Config>(ErrorCode.NoError, config);
                }
                return new ServiceResult<Config>(ErrorCode.DB_Error);
            }
        }
    }
}
